package com.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.julis.R;
import com.customview.inputview.NoEmojiEditText;


/**
 * Created by sq on 2019/5/10.
 * Functions:
 */
public class TestInput extends LinearLayout {

    private TextView leftShow;
    //    private EditText rightEdit;
    private NoEmojiEditText rightEdit;
    private String leftStr;

    public TestInput(@NonNull Context context) {
        super(context);
    }

    public TestInput(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View rootView = LayoutInflater.from(context).inflate(R.layout.test_input, this, true);
        initView(rootView);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TestInput);
        if (typedArray != null) {
            leftStr = typedArray.getString(R.styleable.TestInput_leftTextStr);
        }


        if (!TextUtils.isEmpty(leftStr)) {
            leftShow.setText(leftStr);
        }

    }

    public TestInput(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void initView(View rootView) {
        leftShow = (TextView) rootView.findViewById(R.id.tv_left_show);
        rightEdit = (NoEmojiEditText) rootView.findViewById(R.id.tv_right_edit);
    }

    public TestInput(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setEditText(String cardType) {
        if (cardType != null) {
            rightEdit.setText(cardType);
        }
    }
}
